import CryptoJS from 'crypto-js'

// 从环境变量读取密钥，需在.env文件中定义
const SECRET_KEY = import.meta.env.VITE_CRYPTO_SECRET

export const encrypt = (data) => {
  return CryptoJS.AES.encrypt(data, SECRET_KEY).toString()
}

export const decrypt = (ciphertext) => {
  const bytes = CryptoJS.AES.decrypt(ciphertext, SECRET_KEY)
  return bytes.toString(CryptoJS.enc.Utf8)
}